<?php
/* Add php doc here*/
class Bootstrap
{
	public function __construct($bolAdmin = false)
	{
		date_default_timezone_set('Asia/Saigon');
		set_include_path
		(
			'.'
			. PATH_SEPARATOR . ROOT_LIB
			. PATH_SEPARATOR . ROOT_SITE.'/commons' 
			. PATH_SEPARATOR . ROOT_SITE.'/app/modules/'.SITE_NAME.'/controllers' 
			. PATH_SEPARATOR . ROOT_SITE.'/app/modules/'.SITE_NAME.'/views'
			. PATH_SEPARATOR . ROOT_SITE.'/app/modules/www/models' 
			. PATH_SEPARATOR . ROOT_SITE.'/app/modules/admin/models' 
			. PATH_SEPARATOR . get_include_path()
		);
		include 'Zend/Loader.php';
		Zend_Loader::registerAutoLoad();
		
		$registry = Zend_Registry::getInstance();
		
		#load Config
		include_once ROOT_LIB . '/Common/Conf/global.conf.php';
		include_once ROOT_LIB . '/Common/Conf/cache.conf.php';
		include_once ROOT_SITE. '/configs/cache.conf.php';
		include_once ROOT_SITE. '/configs/common.conf.php';
		include_once ROOT_SITE. '/configs/'.SITE_NAME.'/config.php';
		#load Config
		
		#setup Db
		$db 		= new Common_Db();
		$registry->set('db', $db);
		#setup Db
		
		#setup Session
		//ini_set('session.cookie_domain', '.'.DOMAIN);
		$AppUI = new Common_Session();
		$registry->set('AppUI', $AppUI);
		#setup Session
		
		#setup Templates
		include_once 'Integrate/View/helpers/SmartyCfgInfo.php';
		include_once 'Integrate/View/SmartyView.php';
		$smartyCof = new Integrate_View_Helpers_SmartyCfgInfo
		(
			ROOT_LIB  .'/Smarty/libs',
			ROOT_SITE .'/app/modules/'.SITE_NAME.'/views/',
			ROOT_SITE .'/data/templates_c/'.SITE_NAME,
			ROOT_LIB  .'/Common/Plugins'
		);
		$objView = new Integrate_View_Smarty($smartyCof);
		$objView->assign('AppUI', 		$AppUI);
		#$objView->assign('translate', 	$translate);
		$objView->assign('ROOT_SITE', 	ROOT_SITE);
		$vrender = new Zend_Controller_Action_Helper_ViewRenderer();
		$vrender->setView($objView);
		$vrender->setViewSuffix('tpl');
		Zend_Controller_Action_HelperBroker::addHelper($vrender);
		#setup Templates
		
		#setup Cache
		$cache = new Cache();
		$registry->set('cache', $cache);
		#setup Cache
	}

	public function runApp()
	{
		#setup Controller
		$frontController = Zend_Controller_Front::getInstance();
		#$frontController->throwExceptions(false);
		$frontController->throwExceptions(true);
		$frontController->setControllerDirectory(array
		(
			'default'	=> ROOT_SITE.'/app/modules/'.SITE_NAME.'/controllers',
		));
		
		#load ConfigUrl
		
		$routers = $frontController->getRouter();
        $configRouter =  new Zend_Config_Ini(ROOT_SITE . '/configs/'.SITE_NAME.'/configUrl.ini', 'UrlRewrite');
        $routers->addConfig($configRouter,'routes');
	
		$frontController->dispatch();
	}
}
?>